import dnode from 'dnode'
import logger from './logger'
let graphql = require('graphql')

export default (config, schema) => {
    let server = dnode({
        query: function(query, callback) {
            graphql.graphql(schema, query).then(result => {
                callback(result);
            });
        }
    });

    server.on('error', (err) => {
        logger.error(err);
    });

    server.on('fail', (err) => {
        logger.error(err);
    })

    server.listen(config.listen.dnode);
    logger.info(`rpc  query server listen: ${config.listen.dnode}`);
}
